package com.example.akr_webservices.service;

import com.example.akr_webservices.Dto.*;
import com.example.akr_webservices.mapper.BeanAkrDataMapper;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DataService {
    @Autowired
    BeanAkrDataMapper akrDataMapper;

    public DtoAkrData GetLastData() {

        var value = akrDataMapper.selectLast();
        var dto = new DtoAkrData();

        dto.id  = value.id;
        dto.gateid = value.gateid;
        dto.saleid = value.saleid;
        dto.time = value.time;
        dto.create_time = value.create_time;

        // 使用Gson库将Json字符串转换为对象
        Gson gson = new Gson();
        var t02 = gson.fromJson(value.T101002, T101002.class);
        var t03 = gson.fromJson(value.T101003, T101003.class);
        var t04 = gson.fromJson(value.T101004, T101004.class);
        var t05 = gson.fromJson(value.T101005, T101005.class);

        dto.t101002 = t02;
        dto.t101003 = t03;
        dto.t101004 = t04;
        dto.t101005 = t05;

        return dto;
    }
}